import storage from "@/utils/storage";
import constant from "@/utils/constant";

const monopoly = {
  //localstorage永久化数据
  /**
   * tagList 字典
   * gameContral 游戏参数
   * general 武将
   * stratagem 计谋
   * politics 政策
   * command 指挥
   * tactic 战法
   * land 城池
   * map 地图 = 城池
   * mainControl 当前回合数据
   * playerContral 玩家数据
   * historyInfo 历史数据
   *
   */
  state: {
    tagList: storage.get(constant.tagList),
    gameContral: storage.get(constant.gameContral),
    general: storage.get(constant.general),
    stratagem: storage.get(constant.stratagem),
    politics: storage.get(constant.politics),
    command: storage.get(constant.command),
    tactic: storage.get(constant.tactic),
    land: storage.get(constant.land),
    map: storage.get(constant.map),
    mainControl: storage.get(constant.mainControl),
    playerContral: storage.get(constant.playerContral),
    historyInfo: storage.get(constant.historyInfo),
  },
  mutations: {
    SET_tagList: (state, tagList) => {
      state.tagList = tagList;
      storage.set(constant.tagList, tagList);
    },
    SET_gameContral: (state, gameContral) => {
      state.gameContral = gameContral;
      storage.set(constant.gameContral, gameContral);
    },
    SET_general: (state, general) => {
      state.general = general;
      storage.set(constant.general, general);
    },
    SET_stratagem: (state, stratagem) => {
      state.stratagem = stratagem;
      storage.set(constant.stratagem, stratagem);
    },
    SET_politics: (state, politics) => {
      state.politics = politics;
      storage.set(constant.politics, politics);
    },
    SET_command: (state, command) => {
      state.command = command;
      storage.set(constant.command, command);
    },
    SET_tactic: (state, tactic) => {
      state.tactic = tactic;
      storage.set(constant.tactic, tactic);
    },
    SET_land: (state, land) => {
      state.land = land;
      storage.set(constant.land, land);
    },
    SET_map: (state, map) => {
      state.map = map;
      storage.set(constant.map, map);
    },
    SET_mainControl: (state, mainControl) => {
      state.mainControl = mainControl;
      storage.set(constant.mainControl, mainControl);
    },
    SET_playerContral: (state, playerContral) => {
      state.playerContral = playerContral;
      storage.set(constant.playerContral, playerContral);
    },
    SET_historyInfo: (state, historyInfo) => {
      state.historyInfo = historyInfo;
      storage.set(constant.historyInfo, historyInfo);
    },
  },
  actions: {
    // gameStart({ commit, state }, info) {
    //   const gameContral = {
    //     playerNum: 4,
    //     playerId: 0,
    //     gameState: 0,
    //     turn: 1,
    //   };
    //   return new Promise((resolve, reject) => {
    //     commit("SET_gameContral", gameContral);
    //     resolve();
    //   });
    // },
    // gameEnd() {},
  },
};

export default monopoly;
